Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

187
Views
Unhandled GraphQL subscription error [Error: Cannot destructure property 'data' of 'undefined' as it is undefined.]

I try to use subscribeToMorefor my graphql query in react-native, but I get following issue:

ERROR: Unhandled GraphQL subscription error [Error: Cannot destructure property 'data' of 'undefined' as it is undefined.]

My subscription looks like

// MESSAGE_SUBSCRIPTION
import { gql } from '@apollo/client'

export const TOPIC_MESSAGE_SUBSCRIPTION = gql`
  subscription MessageSubscription($data: SubscriptionInput!) {
    messageSubscription(data: $data) {
      _id
      text
    }
  }
`

My Component

...
subscribeToMore({
  document: MESSAGE_SUBSCRIPTION,
  variables: {
    data: {
      _id: params._id,
    },
  },
  updateQuery: (prev, { subscriptionData }) => {
    if (!subscriptionData.data) return prev
    console.log(prev, subscriptionData)

    return prev
  },
})
...

When I try the subscriton in my playground everthing work fine.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The configuration of my apolloClient where missing the websocket connection.

Also I need to add the authorization as param, to get it as conntext

const wsLink = new WebSocketLink({
  uri: Platform.select({
    ios: 'ws://localhost:4000/',
    android: 'ws://10.0.2.2:4000/',
  }),
  options: {
    reconnect: true,
    connectionParams: async () => {
      const result = await getToken()

      return {
        authorization: result ? `Bearer ${result.password}` : '',
      }
    },
  },
})

....


export const client = new ApolloClient({
  link: split(
    ({ query }) => {
      const definition = getMainDefinition(query)
      return (
        definition.kind === 'OperationDefinition' &&
        definition.operation === 'subscription'
      )
    },
    authLink.concat(wsLink as any),
    authLink.concat(httpLink as any)
  ),
  cache: new InMemoryCache(),
})
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!